package com.allenz.forum.controller;

import com.allenz.forum.common.AppResult;
import com.allenz.forum.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

@Api(tags = "测试类接口")
//表示返回的结果是一个数据
@RestController
//定义一级映射路径
@RequestMapping("/test")
public class TestController {

    @ApiOperation("测试接口1 , 显示你好springboot")
    @GetMapping("/hello")
    public String hello(){
        return "hello , spring boot";
    }

    @ApiOperation("测试接口2 , 显示抛出的异常信息")
    @GetMapping("/exception")
    public AppResult testException() throws Exception {
        throw new Exception("这是一个exception...");
    }

    @ApiOperation("测试接口3 , 显示抛出的自定义异常信息")
    @GetMapping("/appexception")
    public AppResult testAppException(){
        throw new ApplicationException("这是一个ApplicationException");
    }

    @ApiOperation("测试接口4 , 根据姓名显示你好信息")
    @PostMapping("/hellobyname")
    public AppResult helloByName(@ApiParam("姓名") @RequestParam("name") String name){
        return AppResult.success("hello " + name);
    }
}
